package com.parkingspace.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.parkingspace.entity.Appraise;
import com.parkingspace.dao.AppraiseMapper;
import com.parkingspace.service.IAppraiseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评价表 服务实现类
 * </p>
 *
 * @author Gapper
 * @since 2021-06-01
 */
@Service
public class AppraiseServiceImpl extends ServiceImpl<AppraiseMapper, Appraise> implements IAppraiseService {

    @Resource
    private  AppraiseMapper appraiseMapper;

//    @Override
//    public List<Appraise> getAppraiseList(Appraise appraise) {
//
//        QueryWrapper<Appraise> queryWrapper = new QueryWrapper<>();
//        List<Integer> list = Arrays.asList(0, 1, 2);
//        queryWrapper.in("evaluate",list);
////        List<Appraise>  pageList=null;
//
//        List<Appraise> appraiseList=null;
//        if (appraise.getParkingAddress()!=null){
//            queryWrapper.like("parking_address",appraise.getParkingAddress());
//            appraiseList =appraiseMapper.selectList(queryWrapper);
//
//
//        }
//        appraiseList =appraiseMapper.selectList(queryWrapper);
//
//        System.out.println("appraiseList = " + appraiseList);
//        return appraiseList;
//    }
//

    @Override
    public  IPage  getAppraiseList(Appraise appraise,Page page) {
        System.out.println("getAppraiseList(impl)进来了getRecords："+page.getRecords());
        System.out.println("getAppraiseList(impl)进来了getTotal："+page.getTotal());
        System.out.println("getAppraiseList(impl)进来了getSize："+page.getSize());
        System.out.println("getAppraiseList(impl)进来了getPages："+page.getPages());
        System.out.println("getAppraiseList(impl)进来了getCurrent："+page.getCurrent());
        QueryWrapper<Appraise> queryWrapper = new QueryWrapper<>();
        List<Integer> list = Arrays.asList(0, 1, 2);
        queryWrapper.in("evaluate",list);
        List<Appraise>  pageList=null;
//        Page<Appraise> pageDate=null;
        IPage p=null;
        if (appraise.getParkingAddress()!=null){
            queryWrapper.like("parking_address",appraise.getParkingAddress());
//            List<Appraise> appraiseList =appraiseMapper.selectList(queryWrapper);
             p = appraiseMapper.customPageQuery(page, queryWrapper);
//            pageList = pageDate.getRecords();
//            for (Appraise appraise1 : pageList) {
//                System.out.println("appraise1 = " + appraise1);
//            }
//            System.out.println("getAppraiseList(impl)111111111:");
//            System.out.println("getTotal: = " + page.getTotal());
//            System.out.println("getPages:"+page.getPages());
//            System.out.println("getRecords:"+page.getRecords());
//            System.out.println("getCurrent:"+page.getCurrent());
//            System.out.println("getSize:"+page.getSize());

        }

         p = appraiseMapper.customPageQuery(page, queryWrapper);
//        pageList = pageDate.getRecords();
//        for (Appraise appraise2 : pageList) {
//            System.out.println("appraise2 = " + appraise2);
//        }
//        System.out.println("getAppraiseList(impl)2222222222:");
//        System.out.println("getTotal: = " + page.getTotal());
//        System.out.println("getPages:"+page.getPages());
//        System.out.println("getRecords:"+page.getRecords());
//        System.out.println("getCurrent:"+page.getCurrent());
//        System.out.println("getSize:"+page.getSize());



//        List<Appraise> appraiseList =appraiseMapper.selectList(queryWrapper);
//        System.out.println("appraiseList = " + appraiseList);

        return  p;
//        return appraiseList;
    }



    @Override
    public boolean delAppraiseById(Long appraiseId) {
        System.out.println("appraiseId 删除impl进来了= " + appraiseId);
//        QueryWrapper<Appraise> queryWrapper = new QueryWrapper<>();
        return appraiseMapper.deleteById(appraiseId)==1?true:false;

    }


}
